<template>
  <view class="safe-area-inset-bottom">
    <!-- 搜索框 -->
    <view class="swip_header">
      <view class="slot-box">
        <view style="width: 100%;">
          <uni-search-bar
              v-model="queryParams.params.signApi"
              type="text"
              @confirm="handleQuery"
              @input="handleQuery"
              placeholder="请输入套餐名称或编号"/>
        </view>
      </view>
    </view>
    <!-- 签署明细列表 -->
    <view v-if="!!dataList && dataList.length > 0" class="listSearchTop cardList">
      <uni-card :is-shadow="false" v-for="(item,index) in dataList" :key="index">
		<p class="grid-integral">{{ item.name }}</p>
        <p class="grid-integral">交易编号：{{ item.number }}</p>
        <p class="grid-integral">收支类型：
          <template v-for="(dictItem, index) in dicts.ec_sgin_record_inout_type_status">
            <template v-if="item.inOutType == dictItem.value">
              <uni-tag :text="dictItem.text" :type="dictItem.type"/>
            </template>
          </template>
        </p>
        <p class="grid-integral">收支次数：
          <span v-if="item.inOutType == 1" class="themeColor"> + {{ item.amount }}</span>
          <span v-else class="errorColor"> - {{ item.amount }}</span></p>
        <p class="grid-integral">账户签署总量：{{ item.balance }}</p>
        <p class="grid-integral">签署套餐名称：{{ item.signFlowFeeName }}</p>
        <p class="grid-integral">签署套餐编号：{{ item.signFlowFeeOrderNumber }}</p>
        <p class="grid-integral">签署合同编号：{{ (!!item.contractNumber) ? item.contractNumber : '--' }}</p>
        <p class="grid-integral">收支时间：{{ item.createTime }}</p>
      </uni-card>
      <!-- 加载更多 -->
      <uni-load-more color="#00a660" :status="loadStatus"/>
    </view>
    <!-- 暂无数据 -->
    <luanqingEmpty :show="true" text="没有更多数据啦" v-else/>
  </view>
</template>

<script>
import {listSignFlowFeeRecord} from "@/api/ec/person/fee/signFlowFeeRecord";
import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';
import {getDictsByNameForUni} from "../../../../utils/dicts";

export default {
  components: {luanqingEmpty},
  data() {
    return {
      // 数据字典
      dicts: {
        // 收支类型
        ec_sgin_record_inout_type_status: [],
        // 交易渠道
        ec_integral_trading_channel: [],
      },
      // 加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
      loadStatus: 'loading',
      // 数据列表
      dataList: [],
      //总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        number: undefined,
        signFlowFeeOrderNumber: undefined,
        params: {
          signApi: undefined,
          contractApi: undefined
        }
      },
    }
  },
  onLoad() {
    this.getDicts()
  },
  created() {
    this.getList();
  },
  /** 上拉刷新回调 */
  onReachBottom() {
    if (this.loadStatus != 'noMore' && this.total > this.dataList.length) {
      this.loadStatus = 'loading';
      // 延迟500毫秒显示loading效果
      setTimeout(() => {
        // 执行查询的方法
        this.getList(false);
      }, 500)
    } else {
      // 停止加载
      this.loadStatus = 'noMore'
    }
  },
  methods: {
    // ===============================================================================================================
    // ==== 加载数据字典
    // ===============================================================================================================
    /**加载数据字典*/
    getDicts() {
      // 收支类型
      this.dicts.ec_sgin_record_inout_type_status = getDictsByNameForUni("ec_sgin_record_inout_type_status");
      // 交易渠道
      this.dicts.ec_integral_trading_channel = getDictsByNameForUni("ec_integral_trading_channel");
    },
    /** 搜索 */
    handleQuery() {
      this.getList(true);
    },
    /**
     * 查询数据列表
     * @param reload true 重新加载数据； false 加载更多
     */
    getList(reload) {
      if (reload) {
        this.queryParams.pageNum = 1;
        this.loadStatus = 'more'
        this.$modal.loading();
      }
      listSignFlowFeeRecord(this.queryParams).then(response => {
        if (reload) {
          uni.hideLoading()
        }
        this.total = response.total;
        if (response.total > 0) {
          const dataRows = response.rows;
          this.dataList = reload ? dataRows : this.dataList.concat(dataRows);
        } else {
          this.dataList = [];
        }
        // 判断数据是否加载完全
        if (response.total <= this.dataList.length) {
          this.loadStatus = 'noMore'
        }
        // 页数+1
        this.queryParams.pageNum++
      }).catch(() => {
        if (reload) {
          uni.hideLoading()
        }
      });
    },
  }
}
</script>
<style lang="scss" scoped>
	::v-deep .uni-card .uni-card__content{
		padding: 20rpx 0 !important;
	}
	page{
		background-color: $uni-bg-color-grey;
	}
</style>
